(* Programme ocaml macro-généré par bopipe 0.9.71 : 17:38:27, le 23/06/08*)
(* A compiler avec ocamlopt, puis appeler avec la primitive pipe ou un bloc external dans un .bop *)

open Bplib;;
let args = Array.to_list Sys.argv;;
let verbose = List.mem "-v" args;;

let args_assoc = assoc_of_sys_argv Sys.argv;;

let get_arg_int_value = try_get_arg_int_value args_assoc;;
let get_arg_string_value = try_get_arg_string_value args_assoc;;

let index_cycle = ref 0;;
(* FROM ALICE.BPO [16] : INIT (16 - 19) *)
# 16 "alice.bpo"

	(* ceci est la fonction correspondant au circuit d'alice *)
	let alice_fct a b s = s := a <> b;;

(* END FROM INIT *)let end_init = true;;
# 22 "_tmp.ml"
let _test _META_line =
begin
    let arite = 0 + 1 + 1 + 1 in
    if arite <= 0 then () else
    ( try ignore _META_line.[pred arite]
      with Invalid_argument _ ->
        prerr_endline "BLOC EXTERNE - PROCESSUS BOPIPE \"alice.bpo\" ERROR";
        Printf.fprintf stderr "Arite entrante insuffisante. ( < %d ) \n" (0 + 1 + 1 + 1);
        flush stderr;
        exit 1
    );
let index_read = ref 0 in
ignore(index_read);
let a = bool_of_char _META_line.[!index_read] in
incr(index_read);
let b = bool_of_char _META_line.[!index_read] in
incr(index_read);
let s = bool_of_char _META_line.[!index_read] in
incr(index_read);
    if verbose
    then
      begin
Printf.fprintf stderr "| a=%d |" (int_of_bool a);
Printf.fprintf stderr "| b=%d |" (int_of_bool b);
Printf.fprintf stderr "| s=%d |" (int_of_bool s);
prerr_newline ();
      end
    else ();
    begin
    try
      begin
(* FROM ALICE.BPO [23] : CODE (55 - 63) *)
# 23 "alice.bpo"

	(* ceci est du code ocaml, doit etre de type unit *)
	(* et peut declancher l'exception TEST_FAILURE *)
	let s_expected = ref false in
	alice_fct a b s_expected;
	if s <> !s_expected
	then raise (TEST_FAILURE (true, "ALICE !!"))
	else () 

(* END FROM CODE *)
      end;
# 67 "_tmp.ml"
      if verbose
      then prerr_endline (Printf.sprintf "TEST Cycle %d : OK" (!index_cycle))
      else ();

(* Vers stdout selon le protocole pipe 01 *)
let fff t = print_string (if t then "1" else "0") in let ignore_fun (f:'a->unit) = () in ignore_fun(fff);

print_newline (); flush stdout;
    with
      | TEST_FAILURE (stop, err) -> 
          Printf.fprintf stderr "CYCLE %d : \"%s\"  \n" (!index_cycle) err;
          prerr_endline "BOPIPE TEST_FAILURE FROM alice.bpo ";
          if stop then failwith "BREAK" else ()
  end
end ;; (* of method _test *)

let _main _META_line =
begin
    let arite = 0 + 1 + 1 in
    if arite <= 0 then () else
    ( try ignore _META_line.[pred arite]
      with Invalid_argument _ ->
        prerr_endline "BLOC EXTERNE - PROCESSUS BOPIPE \"alice.bpo\" ERROR";
        Printf.fprintf stderr "Arite entrante insuffisante. ( < %d ) \n" (0 + 1 + 1);
        flush stderr;
        exit 1
    );
let index_read = ref 0 in
ignore(index_read);
let a = bool_of_char _META_line.[!index_read] in
incr(index_read);
let b = bool_of_char _META_line.[!index_read] in
incr(index_read);
let s = ref false in
    if verbose
    then
      begin
Printf.fprintf stderr "| a=%d |" (int_of_bool a);
Printf.fprintf stderr "| b=%d |" (int_of_bool b);
prerr_newline ();
      end
    else ();
    begin
    try
      begin
(* FROM ALICE.BPO [35] : CODE (114 - 119) *)
# 35 "alice.bpo"

 	(* Ceci est du code ocaml indiquant le calcul de s *)
	(* a et b sont dans les entrées donc de type bool *)
	(* s est une sortie, donc de type bool ref *)
	alice_fct a b s

(* END FROM CODE *)
      end;
# 123 "_tmp.ml"
      if verbose
      then prerr_endline (Printf.sprintf "TEST Cycle %d : OK" (!index_cycle))
      else ();

(* Vers stdout selon le protocole pipe 01 *)
let fff t = print_string (if t then "1" else "0") in let ignore_fun (f:'a->unit) = () in ignore_fun(fff);
fff (!s);

print_newline (); flush stdout;
    with
      | TEST_FAILURE (stop, err) -> 
          Printf.fprintf stderr "CYCLE %d : \"%s\"  \n" (!index_cycle) err;
          prerr_endline "BOPIPE TEST_FAILURE FROM alice.bpo ";
          if stop then failwith "BREAK" else ()
  end
end ;; (* of method _main *)

let __aiguillage s =
  let com, prot = split_protocole s in
  match com with
   | "test" -> _test prot
   | "" -> _main prot
   | t ->
      begin
        Printf.fprintf stderr " alice.bpox, Methode inconnue \"%s\"\n" t; flush stderr;
        exit 0
      end
;;
let _ =
  prerr_endline "This is \"alice.bpo\" by bopipe 0.9.71";
  while true do
    let _GET_line = input_line stdin in
    __aiguillage _GET_line
  done;;
